package com.wiley.homePO;

import io.appium.java_client.android.AndroidDriver;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.io.IOException;
import java.net.MalformedURLException;

public class HaodouMasterPage extends BasePage {
	
	LoggerControler log;

	/**
	 * 页面元素
	 */
	//好豆达人
	public static final By haodou_master_loc = By.name("好豆达人");
	
	//列表avatar
	public static final By haodou_master_avatar_loc = By.id(BaseId + "avatar");
	
	//详情页面nick_tv
	public static final By haodou_master_nick_tv_loc = By.id(BaseId + "nick_tv");
	
	/**
	 * 操作方法
	 */
	//点击好豆达人
	public void clickHaodouMaster(){
		this.clickEle(haodou_master_loc);
	}
	
	//循环访问avatar
	public void clickHaodouMasterAvatar(){
		int avatarSize = this.getElesLength(haodou_master_avatar_loc);
		for(int i = 0; i < avatarSize; i++){
			this.clickEles(haodou_master_avatar_loc, i);
			log.info("该达人昵称为："+this.getMasterNickName());
			driver.sendKeyEvent(4);
		}
	}

	//获取昵称
	public String getMasterNickName(){
		WebElement ele = this.findEle(haodou_master_nick_tv_loc);
		return ele.getText();
	}
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 */
	public void haodouMasterView(Class name) throws MalformedURLException  {
		log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		//滑动到好豆达人
		driver.scrollTo("好豆达人");
		this.clickHaodouMaster();
		log.info("点击进入好豆达人列表");
		this.clickHaodouMasterAvatar();
		log.info("该case测试通过！");
	}
}
